import tensorflow as tf
from keras.layers import UpSampling1D, Reshape, Conv2D
from tensorflow.keras.layers import Conv1D, MaxPooling1D,Dense
from tensorflow import keras
from tensorflow.python.keras.layers import Conv1DTranspose, Permute, Flatten, Dropout


class BasedOnUNet(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(BasedOnUNet,self).__init__()
        self.conv1        = Conv1D(kernel_size=kse,filters=64,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(4096,1),
                            kernel_initializer=kern_int_e)
        self.max_pooling1 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2        = Conv1D(kernel_size=kse,filters=128,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(2048,64),
                            kernel_initializer=kern_int_e)
        self.max_pooling2 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,128),
                            kernel_initializer=kern_int_e)
        self.max_pooling3 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv4        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(512,256),
                            kernel_initializer=kern_int_e)
        self.max_pooling4 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv5        = Conv1D(kernel_size=kse, filters=1024, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(256,512),
                            kernel_initializer=kern_int_e)
        self.conv6        = Conv1D(kernel_size=kse, filters=1024, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(256,1024),
                            kernel_initializer=kern_int_e)
        self.up_sample1   = UpSampling1D(size=2)
        self.conv7        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv8        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample2   = UpSampling1D(size=2)
        self.conv9        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv10       = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample3   = UpSampling1D(size=2)
        self.conv11       = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv12       = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample4   = UpSampling1D(size=2)
        self.conv13       = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv14       = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.reshape      = Reshape((64,64,64))
        self.conv15       = Conv2D(kernel_size=kse, filters=1, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv16       = Conv2D(kernel_size=kse, filters=1, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)

    def call(self,inputs):
        x1 = self.conv1(inputs)
        x2 = self.max_pooling1(x1)
        x2 = self.conv2(x2)
        x3 = self.max_pooling2(x2)
        x3 = self.conv3(x3)
        x4 = self.max_pooling3(x3)
        x4 = self.conv4(x4)
        x5 = self.max_pooling4(x4)
        x5 = self.conv5(x5)
        x5 = self.conv6(x5)
        x5 = self.up_sample1(x5)
        x5 = self.conv7(x5)
        x6 = tf.concat([x4,x5],axis=-1)
        x6 = self.conv8(x6)
        x6 = self.up_sample2(x6)
        x6 = self.conv9(x6)
        x7 = tf.concat([x3,x6],axis=-1)
        x7 = self.conv10(x7)
        x7 = self.up_sample3(x7)
        x7 = self.conv11(x7)
        x8 = tf.concat([x2, x7], axis=-1)
        x8 = self.conv12(x8)
        x8 = self.up_sample4(x8)
        x8 = self.conv13(x8)
        x9 = tf.concat([x1, x8], axis=-1)
        x9 = self.conv14(x9)
        x9 = self.reshape(x9)
        x9 = self.conv15(x9)
        x9 = self.conv16(x9)
        return x9


class BasedOnUNet01(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(BasedOnUNet01,self).__init__()
        self.conv1        = Conv1D(kernel_size=kse,filters=64,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(4096,1),
                            kernel_initializer=kern_int_e)
        self.max_pooling1 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2        = Conv1D(kernel_size=kse,filters=128,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(2048,64),
                            kernel_initializer=kern_int_e)
        self.max_pooling2 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,128),
                            kernel_initializer=kern_int_e)
        self.conv4        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,256),
                            kernel_initializer=kern_int_e)
        self.up_sample1   = UpSampling1D(size=2)
        self.conv5        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv6        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample2   = UpSampling1D(size=2)
        self.conv7        = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv8        = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.reshape      = Reshape((64,64,64))
        self.conv9        = Conv2D(kernel_size=kse, filters=1, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv10       = Conv2D(kernel_size=kse, filters=1, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)

    def call(self,inputs):
        x1 = self.conv1(inputs)
        x2 = self.max_pooling1(x1)
        x2 = self.conv2(x2)
        x3 = self.max_pooling2(x2)
        x3 = self.conv3(x3)
        x3 = self.conv4(x3)
        x3 = self.up_sample1(x3)
        x3 = self.conv5(x3)
        x4 = tf.concat([x2,x3],axis=-1)
        x4 = self.conv6(x4)
        x4 = self.up_sample2(x4)
        x4 = self.conv7(x4)
        x5 = tf.concat([x1,x4],axis=-1)
        x5 = self.conv8(x5)
        x5 = self.reshape(x5)
        x5 = self.conv9(x5)
        x5 = self.conv10(x5)
        return x5

class BasedOnUNet02(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(BasedOnUNet02,self).__init__()
        self.conv1        = Conv1D(kernel_size=kse,filters=64,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(4096,1),
                            kernel_initializer=kern_int_e)
        self.max_pooling1 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2        = Conv1D(kernel_size=kse,filters=128,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(2048,64),
                            kernel_initializer=kern_int_e)
        self.max_pooling2 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,128),
                            kernel_initializer=kern_int_e)
        self.conv4        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,256),
                            kernel_initializer=kern_int_e)
        self.up_sample1   = UpSampling1D(size=2)
        self.conv5        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv6        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample2   = UpSampling1D(size=2)
        self.conv7        = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv8        = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute1     = Permute((2,1))
        self.dens1        = Dense(1024,activation='tanh')
        self.permute2     = Permute((2, 1))
        self.conv9        = Conv1D(kernel_size=kse, filters=32, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute3     = Permute((2, 1))
        self.dens2        = Dense(512, activation='tanh')
        self.permute4     = Permute((2, 1))
        self.conv10       = Conv1D(kernel_size=kse, filters=16, activation='relu', padding='same',
                                   kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute5     = Permute((2, 1))
        self.dens3        = Dense(256, activation='tanh')
        self.permute6     = Permute((2, 1))
        self.conv11       = Conv1D(kernel_size=kse, filters=1, activation='relu', padding='same',
                                   kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute7     = Permute((2, 1))
        self.dens4        = Dense(4096, activation='tanh')
        self.permute8     = Permute((2, 1))
        self.reshape      = Reshape((64,64,1))

    def call(self,inputs):
        x1 = self.conv1(inputs)
        x2 = self.max_pooling1(x1)
        x2 = self.conv2(x2)
        x3 = self.max_pooling2(x2)
        x3 = self.conv3(x3)
        x3 = self.conv4(x3)
        x3 = self.up_sample1(x3)
        x3 = self.conv5(x3)
        x4 = tf.concat([x2,x3],axis=-1)
        x4 = self.conv6(x4)
        x4 = self.up_sample2(x4)
        x4 = self.conv7(x4)
        x5 = tf.concat([x1,x4],axis=-1)
        x5 = self.conv8(x5)
        x5 = self.permute1(x5)
        x5 = self.dens1(x5)
        x5 = self.permute2(x5)
        x5 = self.conv9(x5)
        x5 = self.permute3(x5)
        x5 = self.dens2(x5)
        x5 = self.permute4(x5)
        x5 = self.conv10(x5)
        x5 = self.permute5(x5)
        x5 = self.dens3(x5)
        x5 = self.permute6(x5)
        x5 = self.conv11(x5)
        x5 = self.permute7(x5)
        x5 = self.dens4(x5)
        x5 = self.permute8(x5)
        x5 = self.reshape(x5)
        return x5

class BasedOnUNet03(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(BasedOnUNet03,self).__init__()
        self.conv1        = Conv1D(kernel_size=kse,filters=64,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(4096,1),
                            kernel_initializer=kern_int_e)
        self.max_pooling1 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2        = Conv1D(kernel_size=kse,filters=128,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(2048,64),
                            kernel_initializer=kern_int_e)
        self.max_pooling2 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,128),
                            kernel_initializer=kern_int_e)
        self.max_pooling3 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv4        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(512,256),
                            kernel_initializer=kern_int_e)
        self.max_pooling4 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv5        = Conv1D(kernel_size=kse, filters=1024, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(256,512),
                            kernel_initializer=kern_int_e)
        self.conv6        = Conv1D(kernel_size=kse, filters=1024, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(256,1024),
                            kernel_initializer=kern_int_e)
        self.up_sample1   = UpSampling1D(size=2)
        self.conv7        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv8        = Conv1D(kernel_size=kse, filters=512, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample2   = UpSampling1D(size=2)
        self.conv9        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv10       = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample3   = UpSampling1D(size=2)
        self.conv11       = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv12       = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample4   = UpSampling1D(size=2)
        self.conv13       = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv14       = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                             kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute1     = Permute((2,1))
        self.dens1        = Dense(1024,activation='tanh')
        self.permute2     = Permute((2, 1))
        self.conv15        = Conv1D(kernel_size=kse, filters=32, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute3     = Permute((2, 1))
        self.dens2        = Dense(512, activation='tanh')
        self.permute4     = Permute((2, 1))
        self.conv16       = Conv1D(kernel_size=kse, filters=16, activation='relu', padding='same',
                                   kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute5     = Permute((2, 1))
        self.dens3        = Dense(256, activation='tanh')
        self.permute6     = Permute((2, 1))
        self.conv17       = Conv1D(kernel_size=kse, filters=1, activation='relu', padding='same',
                                   kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.permute7     = Permute((2, 1))
        self.dens4        = Dense(4096, activation='tanh')
        self.permute8     = Permute((2, 1))
        self.reshape      = Reshape((64,64,1))


    def call(self,inputs):
        x1 = self.conv1(inputs)
        x2 = self.max_pooling1(x1)
        x2 = self.conv2(x2)
        x3 = self.max_pooling2(x2)
        x3 = self.conv3(x3)
        x4 = self.max_pooling3(x3)
        x4 = self.conv4(x4)
        x5 = self.max_pooling4(x4)
        x5 = self.conv5(x5)
        x5 = self.conv6(x5)
        x5 = self.up_sample1(x5)
        x5 = self.conv7(x5)
        x6 = tf.concat([x4,x5],axis=-1)
        x6 = self.conv8(x6)
        x6 = self.up_sample2(x6)
        x6 = self.conv9(x6)
        x7 = tf.concat([x3,x6],axis=-1)
        x7 = self.conv10(x7)
        x7 = self.up_sample3(x7)
        x7 = self.conv11(x7)
        x8 = tf.concat([x2, x7], axis=-1)
        x8 = self.conv12(x8)
        x8 = self.up_sample4(x8)
        x8 = self.conv13(x8)
        x9 = tf.concat([x1, x8], axis=-1)
        x9 = self.conv14(x9)
        x9 = self.permute1(x9)
        x9 = self.dens1(x9)
        x9 = self.permute2(x9)
        x9 = self.conv15(x9)
        x9 = self.permute3(x9)
        x9 = self.dens2(x9)
        x9 = self.permute4(x9)
        x9 = self.conv16(x9)
        x9 = self.permute5(x9)
        x9 = self.dens3(x9)
        x9 = self.permute6(x9)
        x9 = self.conv17(x9)
        x9 = self.permute7(x9)
        x9 = self.dens4(x9)
        x9 = self.permute8(x9)
        x9 = self.reshape(x9)
        return x9

class BasedOnUNet04(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(BasedOnUNet04,self).__init__()
        self.conv1        = Conv1D(kernel_size=kse,filters=64,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(4096,1),
                            kernel_initializer=kern_int_e)
        self.max_pooling1 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2        = Conv1D(kernel_size=kse,filters=128,activation='relu',padding='same',
                            kernel_regularizer=kern_reg,input_shape=(2048,64),
                            kernel_initializer=kern_int_e)
        self.max_pooling2 = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,128),
                            kernel_initializer=kern_int_e)
        self.conv4        = Conv1D(kernel_size=kse, filters=256, activation='relu', padding='same',
                            kernel_regularizer=kern_reg,input_shape=(1024,256),
                            kernel_initializer=kern_int_e)
        self.up_sample1   = UpSampling1D(size=2)
        self.conv5        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv6        = Conv1D(kernel_size=kse, filters=128, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.up_sample2   = UpSampling1D(size=2)
        self.conv7        = Conv1D(kernel_size=kse, filters=64, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.conv8        = Conv1D(kernel_size=kse, filters=1, activation='relu', padding='same',
                            kernel_regularizer=kern_reg, kernel_initializer=kern_int_e)
        self.flatten      = Flatten()
        self.dense1       = Dense(10,activation='softmax')

    def call(self,inputs):
        x1 = self.conv1(inputs)
        x2 = self.max_pooling1(x1)
        x2 = self.conv2(x2)
        x3 = self.max_pooling2(x2)
        x3 = self.conv3(x3)
        x3 = self.conv4(x3)
        x3 = self.up_sample1(x3)
        x3 = self.conv5(x3)
        x4 = tf.concat([x2,x3],axis=-1)
        x4 = self.conv6(x4)
        x4 = self.up_sample2(x4)
        x4 = self.conv7(x4)
        x5 = tf.concat([x1,x4],axis=-1)
        x5 = self.conv8(x5)
        x5 = self.flatten(x5)
        x5 = self.dense1(x5)
        return x5

class RebuildUnet(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(RebuildUnet,self).__init__()
        self.conv1_1    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv1_2    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp1      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2_1    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv2_2    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp2      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3_1    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv3_2    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp3      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv4_1    = Conv1D(filters=512,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv4_2    = Conv1D(filters=512,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp4      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv5_1    = Conv1D(filters=1024,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv5_2    = Conv1D(filters=1024,padding='same',activation='relu'
                                  ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample1 = UpSampling1D(size=2)
        self.conv_p_1   = Conv1D(filters=512, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_1 = Conv1D(filters=512, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_2 = Conv1D(filters=512, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample2 = UpSampling1D(size=2)
        self.conv_p_2   = Conv1D(filters=256, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_1 = Conv1D(filters=256, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_2 = Conv1D(filters=256, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample3 = UpSampling1D(size=2)
        self.conv_p_3   = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_3_1 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_3_2 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample4 = UpSampling1D(size=2)
        self.conv_p_4   = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_4_1 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_4_2 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_1   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_2   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.flatten    = Flatten()
        self.dense1     = Dense(256,activation='relu')
        self.dense2     = Dense(128, activation='relu')
        self.dense3     = Dense(10, activation='softmax')
    def call(self,inputs):
        x1 = self.conv1_1(inputs)
        x1 = self.conv1_2(x1)
        x2 = self.maxp1(x1)
        x2 = self.conv2_1(x2)
        x2 = self.conv2_2(x2)
        x3 = self.maxp2(x2)
        x3 = self.conv3_1(x3)
        x3 = self.conv3_2(x3)
        x4 = self.maxp3(x3)
        x4 = self.conv4_1(x4)
        x4 = self.conv4_2(x4)
        x5 = self.maxp4(x4)
        x5 = self.conv5_1(x5)
        x5 = self.conv5_2(x5)
        x5 = self.conv_p_1(x5)
        x5 = self.up_sample1(x5)
        x6 = tf.concat([x4,x5],axis=-1)
        x6 = self.conv_a_1_1(x6)
        x6 = self.conv_a_1_2(x6)
        x6 = self.conv_p_2(x6)
        x6 = self.up_sample2(x6)
        x7 = tf.concat([x3,x6],axis=-1)
        x7 = self.conv_a_2_1(x7)
        x7 = self.conv_a_2_2(x7)
        x7 = self.conv_p_3(x7)
        x7 = self.up_sample3(x7)
        x8 = tf.concat([x2, x7], axis=-1)
        x8 = self.conv_a_3_1(x8)
        x8 = self.conv_a_3_2(x8)
        x8 = self.conv_p_4(x8)
        x8 = self.up_sample4(x8)
        x9 = tf.concat([x1,x8],axis=-1)
        x9 = self.conv_a_4_1(x9)
        x9 = self.conv_a_4_2(x9)
        x9 = self.conv_l_1(x9)
        x9 = self.conv_l_2(x9)
        x9 = self.flatten(x9)
        x9 = self.dense1(x9)
        x9 = self.dense2(x9)
        x9 = self.dense3(x9)
        return x9

class RebuildUnetChange02(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(RebuildUnetChange02,self).__init__()
        #去噪自编码器
        #编码器部分
        self.code_1     = Conv1D(filters=64, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.code_2     = Conv1D(filters=128, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.conv_lack  = Conv1D(filters=256, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.decode_1   = Conv1DTranspose(filters=128, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.decode_2   = Conv1DTranspose(filters=64, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.out        = Conv1D(filters=1, kernel_size=kse, strides=2, padding="same", activation="relu")
        self.conv1_1    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv1_2    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp1      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2_1    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv2_2    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp2      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3_1    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv3_2    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample1 = UpSampling1D(size=2)
        self.conv_p_1   = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_1 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_2 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample2 = UpSampling1D(size=2)
        self.conv_p_2   = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_1 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_2 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_1   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_2   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.flatten    = Flatten()
        self.dense1     = Dense(256,activation='relu')
        self.dense2     = Dense(128, activation='relu')
        self.dense3     = Dense(3, activation='softmax')
    def call(self,inputs):
        x  = self.code_1(inputs)
        x  = self.code_2(x)
        x  = self.conv_lack(x)
        x  = self.decode_1(x)
        x  = self.decode_2(x)
        x  = self.out(x)
        x1 = self.conv1_1(x)
        x1 = self.conv1_2(x1)
        x2 = self.maxp1(x1)
        x2 = self.conv2_1(x2)
        x2 = self.conv2_2(x2)
        x3 = self.maxp2(x2)
        x3 = self.conv3_1(x3)
        x3 = self.conv3_2(x3)
        x5 = self.conv_p_1(x3)
        x5 = self.up_sample1(x5)
        x6 = tf.concat([x2,x5],axis=-1)
        x6 = self.conv_a_1_1(x6)
        x6 = self.conv_a_1_2(x6)
        x6 = self.conv_p_2(x6)
        x6 = self.up_sample2(x6)
        x7 = tf.concat([x1,x6],axis=-1)
        x7 = self.conv_a_2_1(x7)
        x7 = self.conv_a_2_2(x7)
        x9 = self.conv_l_1(x7)
        x9 = self.conv_l_2(x9)
        x9 = self.flatten(x9)
        x9 = self.dense1(x9)
        x9 = self.dense2(x9)
        x9 = self.dense3(x9)
        return x9

class FullyConnectionNet(keras.Model):
    def __init__(self):
        super(FullyConnectionNet,self).__init__()
        self.flatten    = Flatten()
        self.dense1     = Dense(1024,activation='relu')
        self.dense2     = Dense(2048, activation='relu')
        self.dense3     = Dense(256, activation='relu')
        self.dense4     = Dense(10, activation='softmax')
    def call(self,inputs):
        x = self.flatten(inputs)
        x = self.dense1(x)
        x = self.dense2(x)
        x = self.dense3(x)
        x = self.dense4(x)
        return x

class RebuildUnetNoDAE(keras.Model):
    def __init__(self,kse,kern_reg,kern_int_e):
        super(RebuildUnetNoDAE,self).__init__()
        #去噪自编码器
        #编码器部分
        self.conv1_1    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv1_2    = Conv1D(filters=64,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp1      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv2_1    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv2_2    = Conv1D(filters=128,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.maxp2      = MaxPooling1D(pool_size=2, padding='same', strides=2)
        self.conv3_1    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv3_2    = Conv1D(filters=256,padding='same',activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample1 = UpSampling1D(size=2)
        self.conv_p_1   = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_1 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_1_2 = Conv1D(filters=128, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.up_sample2 = UpSampling1D(size=2)
        self.conv_p_2   = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_1 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_a_2_2 = Conv1D(filters=64, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_1   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.conv_l_2   = Conv1D(filters=1, padding='same', activation='relu'
                                 ,kernel_size=kse,kernel_regularizer=kern_reg,kernel_initializer=kern_int_e)
        self.flatten    = Flatten()
        self.dense1     = Dense(256,activation='relu')
        self.dense2     = Dense(128, activation='relu')
        self.dense3     = Dense(10, activation='softmax')
    def call(self,inputs):
        x1 = self.conv1_1(inputs)
        x1 = self.conv1_2(x1)
        x2 = self.maxp1(x1)
        x2 = self.conv2_1(x2)
        x2 = self.conv2_2(x2)
        x3 = self.maxp2(x2)
        x3 = self.conv3_1(x3)
        x3 = self.conv3_2(x3)
        x5 = self.conv_p_1(x3)
        x5 = self.up_sample1(x5)
        x6 = tf.concat([x2,x5],axis=-1)
        x6 = self.conv_a_1_1(x6)
        x6 = self.conv_a_1_2(x6)
        x6 = self.conv_p_2(x6)
        x6 = self.up_sample2(x6)
        x7 = tf.concat([x1,x6],axis=-1)
        x7 = self.conv_a_2_1(x7)
        x7 = self.conv_a_2_2(x7)
        x9 = self.conv_l_1(x7)
        x9 = self.conv_l_2(x9)
        x9 = self.flatten(x9)
        x9 = self.dense1(x9)
        x9 = self.dense2(x9)
        x9 = self.dense3(x9)
        return x9